package classictravellersalesman;

import java.io.InputStream;
import java.util.Scanner;

public class Graph {
	
	protected static final int INF = Integer.MAX_VALUE;
	private static final int MAXVALUE = 100;
	
	protected double[][] matrix;
	protected int vertexCount;
	public Graph() {
		
	}
	
	public Graph(InputStream in) {
		Scanner sc = new Scanner(in);
		vertexCount = sc.nextInt();
		sc.nextLine();
		initMatrix(vertexCount);
		for(int i=0;i<vertexCount; ++i) {
			String line = sc.nextLine();
			String[] tokens = line.split(" ");
			for(int j=0;j<tokens.length; j = j +2) {
				matrix[i][Integer.parseInt(tokens[j])] = Double.parseDouble(tokens[j+1]);
			}			
		}
		
	}
	
	public void generate(int n, int sparse) {
		vertexCount = n;
		initMatrix(n);
		for(int i=0; i<n; ++i) {
			for(int j=i;j<n;++j) {
				int elem = (int)(Math.random()*MAXVALUE);
				matrix[i][j] = elem;
				matrix[j][i] = elem;
			}
		}
	}

	protected void initMatrix(int n) {
		matrix = new double[n][];
		for(int i=0; i<n; ++i) {
			matrix[i] = new double[n];
			for(int j=0; j<n; ++j) {
				matrix[i][j] = Graph.INF;
			}
		}
	}
	
	public double getDistance(int i, int j) {
		return matrix[i][j];
	}
	public int getDimension() {
		return vertexCount;
	}
}
